/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package data_bases.business;

import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Javier
 */
public class SchemaDataModel extends ListDataModel<Schema> implements SelectableDataModel<Schema>{
      
    public SchemaDataModel() {  
    }  
  
    public SchemaDataModel(List<Schema> data) {  
        super(data);  
    }  
      
    @Override  
    public Schema getRowData(String rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
          
        List<Schema> schemas = (List<Schema>) getWrappedData();  
          
        for(Schema schema : schemas) {  
            if(schema.getName().equals(rowKey))  
                return schema;  
        }  
          
        return null;  
    }  
  
    @Override  
    public Object getRowKey(Schema schema) {  
        return schema.getName();  
    }
}
